package com.gin.no_gay_alliance.app;

import com.gin.no_gay_alliance.manager.BlockDataManager;
import com.gin.no_gay_alliance.manager.EmoteManager;
import com.gin.no_gay_alliance.manager.FavorForumManager;
import com.gin.no_gay_alliance.manager.FavorManager;
import com.gin.no_gay_alliance.manager.FollowManager;
import com.gin.no_gay_alliance.manager.ItemInventoryManager;
import com.gin.no_gay_alliance.manager.MissionManager;
import com.gin.no_gay_alliance.manager.NoticeManager;
import com.gin.no_gay_alliance.manager.NotificationUtils;
import com.gin.no_gay_alliance.manager.PostManager;
import com.gin.no_gay_alliance.manager.PriMsgManager;
import com.gin.no_gay_alliance.manager.ThemeManager;
import com.gin.no_gay_alliance.manager.TopicListManager;
import com.gin.no_gay_alliance.manager.TopicReadManager;
import com.gin.no_gay_alliance.manager.UpgradeManager;
import com.gin.no_gay_alliance.manager.UserInfoManager;
import com.gin.no_gay_alliance.manager.UserRecentTopicManager;
import com.gin.no_gay_alliance.manager.ViewBindingManager;
import com.gin.no_gay_alliance.manager.provider.ResourceManager;

import java.lang.ref.WeakReference;

/**
 * 管理器工厂
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/8/7 14:20
 **/
public class ManagerFactory {
    WeakReference<FavorForumManager> favorForumManagerWeakReference;
    WeakReference<TopicListManager> topicListManagerWeakReference;
    WeakReference<UserInfoManager> userInfoManagerWeakReference;
    WeakReference<UserRecentTopicManager> userTopicManagerWeakReference;
    WeakReference<TopicReadManager> topicReadManagerWeakReference;
    WeakReference<PostManager> postManagerWeakReference;
    WeakReference<ThemeManager> themeManagerWeakReference;
    WeakReference<NoticeManager> noticeManagerWeakReference;
    WeakReference<NotificationUtils> notificationUtilsWeakReference;
    WeakReference<ResourceManager> resourceManagerWeakReference;
    WeakReference<EmoteManager> emoteManagerWeakReference;
    WeakReference<PriMsgManager> priMsgManagerWeakReference;
    WeakReference<FavorManager> favorManagerWeakReference;
    WeakReference<ItemInventoryManager> itemInventoryManagerWeakReference;
    WeakReference<ViewBindingManager> viewBindingManagerWeakReference;
    WeakReference<UpgradeManager> upgradeManagerWeakReference;
    WeakReference<BlockDataManager> blockDataManagerWeakReference;
    WeakReference<MissionManager> missionManagerWeakReference;
    WeakReference<FollowManager> followManagerWeakReference;

    public BlockDataManager getBlockDataManager() {
        if (this.blockDataManagerWeakReference == null || this.blockDataManagerWeakReference.get() == null) {
            BlockDataManager manager = new BlockDataManager();
            this.blockDataManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.blockDataManagerWeakReference.get();
    }

    public EmoteManager getEmoteManager() {
        if (this.emoteManagerWeakReference == null || this.emoteManagerWeakReference.get() == null) {
            EmoteManager manager = new EmoteManager();
            this.emoteManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.emoteManagerWeakReference.get();
    }

    /**
     * 获取收藏版面管理器
     *
     * @return 收藏版面管理器
     */
    public FavorForumManager getFavorForumManager() {
        if (this.favorForumManagerWeakReference == null || this.favorForumManagerWeakReference.get() == null) {
            FavorForumManager manager = new FavorForumManager(MyApplication.app);
            this.favorForumManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.favorForumManagerWeakReference.get();
    }

    public FavorManager getFavorManager() {
        if (this.favorManagerWeakReference == null || this.favorManagerWeakReference.get() == null) {
            FavorManager manager = new FavorManager();
            this.favorManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.favorManagerWeakReference.get();
    }

    public FollowManager getFollowManager() {
        if (this.followManagerWeakReference == null || this.followManagerWeakReference.get() == null) {
            FollowManager manager = new FollowManager();
            this.followManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.followManagerWeakReference.get();
    }

    /**
     * 道具仓库管理器
     *
     * @return 道具仓库管理器
     */
    public ItemInventoryManager getItemInventoryManager() {
        if (this.itemInventoryManagerWeakReference == null || this.itemInventoryManagerWeakReference.get() == null) {
            ItemInventoryManager manager = new ItemInventoryManager();
            this.itemInventoryManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.itemInventoryManagerWeakReference.get();
    }

    public MissionManager getMissionManager() {
        if (this.missionManagerWeakReference == null || this.missionManagerWeakReference.get() == null) {
            MissionManager manager = new MissionManager();
            this.missionManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.missionManagerWeakReference.get();
    }

    public NoticeManager getNoticeManager() {
        if (this.noticeManagerWeakReference == null || this.noticeManagerWeakReference.get() == null) {
            NoticeManager manager = new NoticeManager(MyApplication.app);
            this.noticeManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.noticeManagerWeakReference.get();
    }

    public NotificationUtils getNotificationUtils() {
        if (this.notificationUtilsWeakReference == null || this.notificationUtilsWeakReference.get() == null) {
            NotificationUtils manager = new NotificationUtils(MyApplication.app);
            this.notificationUtilsWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.notificationUtilsWeakReference.get();
    }

    public PostManager getPostManager() {
        if (this.postManagerWeakReference == null || this.postManagerWeakReference.get() == null) {
            PostManager manager = new PostManager();
            this.postManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.postManagerWeakReference.get();
    }

    public PriMsgManager getPriMsgManager() {
        if (this.priMsgManagerWeakReference == null || this.priMsgManagerWeakReference.get() == null) {
            PriMsgManager manager = new PriMsgManager();
            this.priMsgManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.priMsgManagerWeakReference.get();
    }

    public ResourceManager getResourceManager() {
        if (this.resourceManagerWeakReference == null || this.resourceManagerWeakReference.get() == null) {
            ResourceManager manager = new ResourceManager();
            this.resourceManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.resourceManagerWeakReference.get();
    }

    public ThemeManager getThemeManager() {
        if (this.themeManagerWeakReference == null || this.themeManagerWeakReference.get() == null) {
            ThemeManager manager = new ThemeManager();
            this.themeManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.themeManagerWeakReference.get();
    }

    /**
     * 获取主题列表管理器
     *
     * @return 主题列表管理器
     */
    public TopicListManager getTopicListManager() {
        if (this.topicListManagerWeakReference == null || this.topicListManagerWeakReference.get() == null) {
            TopicListManager manager = new TopicListManager();
            this.topicListManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.topicListManagerWeakReference.get();
    }

    /**
     * 获取阅读主题/回复 管理器
     *
     * @return 阅读主题/回复 管理器
     */
    public TopicReadManager getTopicReadManager() {
        if (this.topicReadManagerWeakReference == null || this.topicReadManagerWeakReference.get() == null) {
            TopicReadManager manager = new TopicReadManager();
            this.topicReadManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.topicReadManagerWeakReference.get();
    }

    public UpgradeManager getUpgradeManager() {
        if (this.upgradeManagerWeakReference == null || this.upgradeManagerWeakReference.get() == null) {
            UpgradeManager manager = new UpgradeManager();
            this.upgradeManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.upgradeManagerWeakReference.get();
    }

    /**
     * 获取用户信息管理器
     *
     * @return 用户信息管理器
     */
    public UserInfoManager getUserInfoManager() {
        if (this.userInfoManagerWeakReference == null || this.userInfoManagerWeakReference.get() == null) {
            UserInfoManager manager = new UserInfoManager();
            this.userInfoManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.userInfoManagerWeakReference.get();
    }

    /**
     * 获取用户最近主题管理器
     *
     * @return 用户最近主题管理器
     */
    public UserRecentTopicManager getUserRecentTopicManager() {
        if (this.userTopicManagerWeakReference == null || this.userTopicManagerWeakReference.get() == null) {
            UserRecentTopicManager manager = new UserRecentTopicManager();
            this.userTopicManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.userTopicManagerWeakReference.get();
    }

    public ViewBindingManager getViewBindingManager() {
        if (this.viewBindingManagerWeakReference == null || this.viewBindingManagerWeakReference.get() == null) {
            ViewBindingManager manager = new ViewBindingManager();
            this.viewBindingManagerWeakReference = new WeakReference<>(manager);
            return manager;
        }
        return this.viewBindingManagerWeakReference.get();
    }
}
